package process;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @author ChinaManor
 * #Description Table_Demo04
 * #Date: 22/6/2021 16:19
 */
public class Table_Demo04 {
    public static void main(String[] args) {
        //1.准备环境 创建流执行环境和流表环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        //2.Source 自定义Order 每一秒中睡眠一次
        env.addSource(new RichSourceFunction<Order>() {
            @Override
            public void run(SourceContext<Order> ctx) throws Exception {

            }

            @Override
            public void cancel() {

            }
        });

        //3.Transformation 分配时间戳和水印2秒
        //4.注册表 创建临时视图并分配 rowtime
        //5.编写SQL，根据 userId 和 createTime 滚动分组统计 userId、订单总笔数、最大、最小金额
        //6.执行查询语句返回结果
        //7.Sink toRetractStream  → 将计算后的新的数据在DataStream原数据的基础上更新true或是删除false
        //8.打印输出
        //9.执行


    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Order {
        private String orderId;
        private Integer userId;
        private Integer money;
        private Long createTime;
    }
}
